package 每日一题;

public class 连续子数组的最大和 {
    public static int FindGreatestSumOfSubArray(int[] array) {
        int[] dp=new int[array.length];
        dp[0]=array[0];
        int res=0;
        for (int i=1;i<array.length;i++){

            dp[i]=Math.max(array[i],dp[i-1]+array[i]);
            res=Math.max(res,dp[i]);
        }

        return res;
    }

    public static void main(String[] args) {
        int[] nums={1,-2,3,10,-4,7,2,-5};
        System.out.println(FindGreatestSumOfSubArray(nums));
    }
}
